$(function() {
	_addChangeListener("#elderFamilyMember_select", function() {
		var option = $('#elderFamilyMember_select option:selected');
		if(view && view.data) {view.data.elderFamilyMemberName = option.text();}
	});
});

function load_elderFamilyMember_select() {
	if($('#elderFamilyMember_select').length==0) {return;}

	$('#elderFamilyMember_select').html('<option value="" selected></option>');

	findAll_basic(path+'/elderFamilyMember/findAll', function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#elderFamilyMember_select').append('<option value="' + response.data[i].elderFamilyMemberId
				+ '">' + response.data[i].elderFamilyMemberName + '</option>');
		}
	});
}

function load_elderFamilyMember_cond_select() {
	if($('#elderFamilyMember_cond_select').length==0) {return;}

	$('#elderFamilyMember_cond_select').html('<option value="" selected></option>');

	findAll_basic(path+'/elderFamilyMember/findAll', function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#elderFamilyMember_cond_select').append('<option value="' + response.data[i].elderFamilyMemberId
				+ '">' + response.data[i].elderFamilyMemberName + '</option>');
		}
	});
}

load_elderFamilyMember_by_elderId = function(elderId) {
	if(!elderId || elderId=='' || $('#elderFamilyMember_select').length==0) {return;}

	$('#elderFamilyMember_select').html('<option value="" selected></option>');

	find_basic_by_json(path+'/elderFamilyMember/find', {elderId: elderId}, function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#elderFamilyMember_select').append('<option value="' + response.data[i].elderFamilyMemberId
				+ '">' + response.data[i].name + ' ' + response.data[i].relationship
				+ '</option>');
		}
		
		_addChangeListener("#elderFamilyMember_select", function() {
			var option = $('#elderFamilyMember_select option:selected');
			
			if(elderFamilyMemberView && elderFamilyMemberView.data) {
				elderFamilyMemberView.data.elderId = $('#elderFamilyMember_select').val();
				elderFamilyMemberView.data.elderName = option.text();
			}
		});
	});
}
